package com.cskaoyan.service;

import com.cskaoyan.bean.*;
import com.cskaoyan.mapper.TopicCommentMapper;
import com.cskaoyan.mapper.MarketTopicMapper;
import com.cskaoyan.mapper.WeChartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 创建日期: 2022/05/07 15:22
 *
 * @author 孙豪骏
 */
@Service
public class WeChartServiceImpl implements WeChartService {
    @Autowired
    WeChartMapper weChartMapper;
    @Autowired
    MarketTopicMapper topicMapper;
    @Autowired
    TopicCommentMapper contentMapper;

    @Override
    public void insertSearchHistory(WeChartSearchHistory weChatSearchHistory) {
        weChartMapper.insertIntoSearchHistory(weChatSearchHistory);
    }

    @Override
    public List<WeChartSearchHistory> queryHotSearchHistory() {
        return weChartMapper.queryHotSearchHistory();
    }


    @Override
    public List<WeChartSearchHistory> queryNormalHistory() {
        return weChartMapper.queryNormalHistory();
    }

    @Override
    public void clearHistory() {
        weChartMapper.clearHistory();
    }

    @Override
    public List<MarketTopic> queryTopicList() {
        MarketTopicExample marketTopicExample = new MarketTopicExample();


        List<MarketTopic> marketTopicList = topicMapper.selectByExample(marketTopicExample);

        return marketTopicList;


    }

    @Override
    public MarketTopic queryTopicDetail(Integer id) {
        return topicMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MarketTopic> queryRelatedTopic(Integer id) {

        MarketTopicExample marketTopicExample = new MarketTopicExample();
        MarketTopicExample.Criteria criteria = marketTopicExample.createCriteria();
        criteria.andIdGreaterThanOrEqualTo(id);
        return topicMapper.selectByExample(marketTopicExample);

    }

    @Override
    public List<TopicComment> querryTopicComment(Integer valueId) {
        TopicCommentExample topicCommentExample = new TopicCommentExample();
        TopicCommentExample.Criteria criteria = topicCommentExample.createCriteria();
        criteria.andValueidEqualTo(valueId);
        List<TopicComment> topicComments = contentMapper.selectByExample(topicCommentExample);
        return topicComments;
    }

    @Override
    public void insertComment(TopicComment topicComment) {
        contentMapper.insert(topicComment);
    }

    @Override
    public TopicComment selectCommentById(Integer id) {
        return contentMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer countTopicCommentHasPicture(Integer valueId, Integer typeId) {
        TopicCommentExample topicCommentExample = new TopicCommentExample();
        TopicCommentExample.Criteria criteria = topicCommentExample.createCriteria();
        criteria.andValueidEqualTo(valueId);
        criteria.andTypeEqualTo(typeId);
        criteria.andHaspictureEqualTo(true);
        return contentMapper.countByExample(topicCommentExample);
    }

    @Override
    public Integer countTopicCommentHasNoPicture(Integer valueId, Integer typeId) {
        TopicCommentExample topicCommentExample = new TopicCommentExample();
        TopicCommentExample.Criteria criteria = topicCommentExample.createCriteria();
        criteria.andValueidEqualTo(valueId);
        criteria.andTypeEqualTo(typeId);
        return contentMapper.countByExample(topicCommentExample);
    }

}